package com.cowain.respository;

import com.cowain.info.UserInfo;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collection;
import java.util.Date;
import java.util.List;

/**
 * @Author fxw
 * @Date 2022/5/12 20:52
 * 负责数据查询的接口
 */
public interface UserRepository extends JpaRepository<UserInfo, Long> , JpaSpecificationExecutor<UserInfo> {
    //批量更新
    @Modifying
    @Transactional
    @Query("update UserInfo set ustatus = 1 where uid in (?1)")
     int updates(Collection<Long> ids);

    /**
     * 根据条件去查询用户
     */
    @Query("select u from UserInfo u where u.uphone= ?1")
    List<UserInfo> findUser(String phone);

    /**
     * 根据条件去查询用户
     */
    @Query(nativeQuery = true,value = "select * from t_user  where umail= ?1" )
    List<UserInfo> findUser2(String email);

     List<UserInfo> findAllByUtimeBetween(Date t1 , Date t2);

}
